import { defineStore } from 'pinia'
import { ref, computed, watch } from 'vue'
import { useI18n } from 'vue-i18n'

/**
 * 发起外协
 */

const useExternalAssistance = defineStore(
  'externalAssistance',
  () => {
    const { t, locale } = useI18n()

    // 当前步骤 0为第一步
    const activeStep = ref(0)
    const setActiveStep = (val) => {
      activeStep.value = val
    }

    // 下一步
    const next = () => {
      activeStep.value++
    }

    // 上一步
    const back = () => {
      activeStep.value--
    }

    // 步骤名
    const steplist = ref([
      {
        label: 'step1',
        desc: 'step1Desc'
      },
      {
        label: 'step2',
        desc: 'step2Desc'
      },
      {
        label: 'step3',
        desc: 'step3Desc'
      }
      // {
      //   label: 'step4',
      //   desc: 'step4Desc'
      // }
    ])

    // 类别列表
    const categoryList = ref([])
    const setCategoryList = (val) => {
      categoryList.value = val
    }

    // 当前一级类别
    const category = ref(null)
    const setCategory = (val) => {
      category.value = val
    }

    // 外协单信息  orderNo外协单编号
    const orderInfo = ref({})
    const setOrderInfo = (val) => {
      orderInfo.value = val
    }
    const setOrderInfoKey = (key, val) => {
      orderInfo.value[key] = val
    }

    // 询价参数
    const inquiryParams = ref({})
    const setInquiryParams = (val) => {
      inquiryParams.value = val
    }

    // 重置
    const reset = () => {
      activeStep.value = 0
      category.value = null
      orderInfo.value = {}
      inquiryParams.value = {}
    }

    watch(activeStep, (n) => {
      if (n === 0) {
        category.value = null
      }
    })
    // watch(category, (n) => {
    //   if (n !== null) {
    //     const obj = {
    //       航修: 1,
    //       外协: 2,
    //       技术服务: 3,
    //       '代理&报关': 4
    //     }
    //     steplist.value[1].desc = `step2Desc${obj[n.projectNameCn]}`
    //   } else {
    //     steplist.value[1].desc = `step2Desc`
    //   }
    // })

    return {
      activeStep,
      setActiveStep,
      next,
      back,
      steplist,
      reset,
      categoryList,
      setCategoryList,
      category,
      setCategory,
      orderInfo,
      setOrderInfo,
      setOrderInfoKey,
      inquiryParams,
      setInquiryParams
    }
  },
  {
    persist: {
      enabled: false,
      strategies: [
        {
          storage: localStorage
        }
      ]
    }
  }
)

export default useExternalAssistance
